export default class RoomLinkExtension extends Room 
{
    public linkTransferEnergy():void 
    {
        const mineEntities = this.getEntitys("InnerMineEntity");

        const spawnEntity=  this.getEntity("SpawnEntity");
        const coreEntity=  this.getEntity("CoreEntity");
        const controllerEntity=  this.controller!;
        const storelinks  = _.filter([spawnEntity.Link,controllerEntity.Link(),coreEntity.Link],e=>e&& e.store.getUsedCapacity(RESOURCE_ENERGY)<=100) as StructureLink[];
        for(const minemodule of mineEntities)
        {
            const minelink =minemodule.Link ;
            if(minelink)
            {
                 const freecount =  minelink.store.getFreeCapacity(RESOURCE_ENERGY);
                 if(freecount <=100)
                 {
                     // 执行LINK预定700能量
                     if(storelinks.length>0)
                     {
                        minelink.transferEnergy(storelinks[0] );
                        storelinks.shift();
                     }
                 }
            }
        }
        if(storelinks.length>0 && coreEntity.getTakeStores({resourceType:RESOURCE_ENERGY,amount:100000}).length>0)
        {
            const link = coreEntity.Link;
            const controllerlink = controllerEntity.Link();
            if(link&& controllerlink&& link.store.getUsedCapacity(RESOURCE_ENERGY)>700 && controllerlink.store.getFreeCapacity(RESOURCE_ENERGY)>700)
            {
                link.transferEnergy(controllerlink);
            }
        }
    }
}